﻿using Docx2Epub.Docx;
using Docx2Epub.Epub;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnitTests
{
    [TestFixture]
    public class ValidatingTest
    {
        [Test]
        public void Test()
        {
            var document = new DocDocument(@"TestData\test.docx");
            document.Analyze();

            var metadatas = new EPubMetadatas()
            {
                BookId = "urn:uuid:" + Guid.NewGuid().ToString(),
                Contributor = "contributor",
                Creator = "creator",
                Language = "ja",
                ModifiedDate = DateTime.Today,
                PublishDate = DateTime.Today.AddDays(-1),
                Title = "title",
                Publisher = "publisher",
                Rights = "rights",
                CoverImagePath = @"TestData\cover.png",
                TemplateDirectory = @"Templates\default"
            };

            var writer = new EpubBuilder(document.Elements, metadatas);
            Directory.CreateDirectory("output");
            writer.WriteOut("output");
            new EpubPackager("output", "test.epub").WriteOut();


            Process p = new Process();

            p.StartInfo.FileName = @"java";
            p.StartInfo.Arguments = @"-jar EpubChecker\epubcheck-3.0.1.jar test.epub";
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;

            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;

            p.Start();
            string outputso = p.StandardOutput.ReadToEnd();
            string outputse = p.StandardError.ReadToEnd();

            Console.Error.Write(outputso);
            Console.Error.Write(outputse);

            Assert.IsFalse(outputso.Contains("ERROR"), outputso);
            Assert.IsFalse(outputso.Contains("WARNING"), outputso);
            Assert.IsFalse(outputse.Contains("ERROR"), outputse);
            Assert.IsFalse(outputse.Contains("WARNING"), outputse);

        }

    }
}
